<?php
namespace app\laytemp\controller;

use think\Controller;
use think\Db;

class Table extends Controller{
    //表格列表
    public function table_list(){
        $tbName = input('tbName','','string');
        $page=input('page',1,'int');
        $limit = input('limit',10,'int');
        $searchKey = input('searchKey','','string');
        $keyword = input('keyword','','string');
        $status = input('status',-1,'int');
        $where = [];
        if($searchKey!=''){
            $where[$searchKey] = ['like',"%{$keyword}%"];
        }
        if($status!= -1){
            $where['status'] = $status;
        }
        $count = Db::name($tbName)->where($where)->count();
        $data = Db::name($tbName)->where($where)->page($page,$limit)->select();
        return json([
            'code'=>0,
            'msg'=>'获取数据成功',
            'count'=>$count,
            'data'=>$data,
            'limit'=>$limit
        ]);
    }
    //表格删除功能
    public function del($id){
        $tbName = input('tbName','','string');
        $id=input('id',0,'int');
        $where = ['id'=>$id];
        $r = Db::name($tbName)->where($where)->delete();
        if($r){
            return json(['code'=>0,'msg'=>'成功删除']);
        }else{
            return json(['code'=>1,'msg'=>'删除失败']);
        }
    }
}
